//
//  BEDictionaryExtension.swift
//  BasicExtensions
//
//  Created by JY_NEW on 2020/9/4.
//

import UIKit

extension Dictionary where Value == Any {
    public func value<T>(for key: Key) -> T? {
        return self[key] as? T
    }
    public func value(for key: Key) -> Int? {
        if let value = self[key] as? Int {
            return value
        }
        if let value = self[key] as? String {
            return Int(value)
        }
        return nil
    }
    public func value(for key: Key) -> Float? {
        if let value = self[key] as? Float {
            return value
        }
        if let value = self[key] as? Int {
            return Float(value)
        }
        if let value = self[key] as? String {
            return Float(value)
        }
        return nil
    }
    public func value(for key: Key) -> Double? {
        if let value = self[key] as? Double {
            return value
        }
        if let value = self[key] as? Int {
            return Double(value)
        }
        if let value = self[key] as? String {
            return Double(value)
        }
        return nil
    }
}
